/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-03-06
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-10
 * @Description: 
 */

import 'package:chat_client/enums/chat_enum.dart';

const chatPath = 'chat';

// 创建路由路径
generatePath({
  String path = chatPath,
  required String type,
  required String id,
}) {
  return '/$path/$type:$id';
}

// chat路由提取参数
({String id, int type}) splitChatPath(String pathStr) {
  final pathList = pathStr.split('/');
  // 参数校验
  if (pathList.length < 3) {
    throw FormatException('Invalid path format');
  }
  final parts = pathList[2].split(':');
  if (parts.length != 2) {
    throw FormatException('Missing colon separator');
  }
  int type = _matchType(parts[0]);

  return (type: type, id: parts[1]);
}

// 验证是否为chat页面的路径
bool validateChat(String pathStr) {
  final pathList = pathStr.split('/');
  if (pathList[1] == chatPath) return true;
  return false;
}

_matchType(String label) {
  if (label == ConversationType.user.label) {
    return ConversationType.user.value;
  } else if (label == ConversationType.group.label) {
    return ConversationType.group.value;
  } else {
    throw Error();
  }
}
